// ./mongodb/entity/user/userModel.js
const mongoose = require("mongoose");

const userSchema = new mongoose.Schema(
  {
    email: { type: String, required: true, unique: true }, // 邮箱, 必须, 唯一
    username: { type: String, required: true, unique: true }, // 昵称, 必须, 唯一
    password: { type: String, required: true }, // 密码, 必须
    role: { type: String, enum: ["admin", "merchant", "user"], required: true }, // 角色, 必须
    deleted: { type: Boolean, default: false }, // 删除标志, 默认 false
  },
  {
    timestamps: true, // 使用默认的 createdAt 和 updatedAt 字段
  },
  {
    indexes: [
      {
        unique: true,
        fields: ["email", "username"], // 组合唯一索引
      },
    ],
  },
);

const UserModel = mongoose.model("User", userSchema);

module.exports = UserModel;
